import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import FrontView from '../components/front/home/FrontView.vue'
import MyView from '../components/front/myView/MyView.vue'
import { useMenuStore } from "../stores/menu";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/CountRate',
      name: 'CountRate',
      component: () => import('../components/serve/echarts/CountRate.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/loginView.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/registerView.vue')
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      children: [
        {//活动管理
          path: 'ActivityMenageView',
          name: 'ActivityMenageView',
          component: () => import('../components/serve/activity/ActivityMenageView.vue')
        },
        {//活动类型管理
          path: 'ActivityTypeView',
          name: 'ActivityTypeView',
          component: () => import('../components/serve/activityType/ActivityTypeView.vue')
        },
        {//服务类型管理
          path: 'ServiceTypeView',
          name: 'ServiceTypeView',
          component: () => import('../components/serve/serviceType/ServiceTypeView.vue')
        },
        {//服务订单管理
          path: 'ServiceOrderView',
          name: 'ServiceOrderView',
          component: () => import('../components/serve/serviceOrder/ServiceOrderView.vue')
        },
        {//健康订单管理
          path: 'HealthOrderView',
          name: 'HealthOrderView',
          component: () => import('../components/serve/healthOrder/HealthOrderView.vue')
        },
        {//健康报告管理
          path: 'HealthMenageView',
          name: 'HealthMenageView',
          component: () => import('../components/serve/healthReport/HealthMenageView.vue')
        },
        {//普通用户管理
          path: 'UserMenageView',
          name: 'UserMenageView',
          component: () => import('../components/serve/user/UserMenageView.vue')
        },
        {//账号审核
          path: 'userAudit',
          name: 'UserAuditView',
          component: () => import('../components/serve/user/UserAuditView.vue')
        },
        {//工作人员管理
          path: 'WorkerMenageView',
          name: 'WorkerMenageView',
          component: () => import('../components/serve/worker/WorkerMenageView.vue')
        },
        {//医护人员管理
          path: 'DoctorMenageView',
          name: 'DoctorMenageView',
          component: () => import('../components/serve/doctor/DoctorMenageView.vue')
        },
        {//首页Echarts
          path: 'IndexView',
          name: 'IndexView',
          component: () => import('../components/serve/echarts/IndexView.vue')
        },
        {//餐饮需求管理
          path: 'DiningFeedbackManage',
          name: 'DiningFeedbackManage',
          component: () => import('../components/serve/dining/DiningFeedbackManage.vue')
        },
        {//菜谱管理
          path: 'MenuManage',
          name: 'MenuManage',
          component: () => import('../components/serve/dining/MenuManage.vue')
        },
        {//餐饮需求回复
          path: 'DiningFeedbackAdminView',
          name: 'DiningFeedbackAdminView',
          component: () => import('../components/serve/dining/DiningFeedbackAdmin.vue')
        },
        {//餐饮建议改进管理
          path: 'DiningImprovementView',
          name: 'DiningImprovementView',
          component: () => import('../components/serve/dining/DiningImprovement.vue')
        },
        {//新闻管理
          path: 'NewsManageView',
          name: 'NewsManageView',
          component: () => import('../components/serve/news/NewsManage.vue')
        },
        {//新闻分类管理
          path: 'NewsCategoryView',
          name: 'NewsCategoryView',
          component: () => import('../components/serve/news/NewsCategoryManage.vue')
        }
      ]
    },
    {
      path: '/front',
      name: 'front',
      component: FrontView,
      children: [
        {//首页
          path: '/front/home/FrontHomeView',
          name: 'FrontHomeView',
          component: () => import('../components/front/home/FrontHomeView.vue')
        },
        {//社区活动
          path: '/front/activity/FrontActivityView',
          name: 'FrontActivityView',
          component: () => import('../components/front/activity/FrontActivityView.vue')
        },
        {//活动详情
          path: '/front/activity/ActivityDetailView',
          name: 'ActivityDetailView',
          component: () => import('../components/front/activity/ActivityDetailView.vue')
        },
        {//社区服务
          path: '/front/service/FrontServiceView',
          name: 'FrontServiceView',
          component: () => import('../components/front/service/FrontServiceView.vue')
        },
        {//餐饮服务
          path: '/front/dining/FrontDiningView',
          name: 'FrontDiningView',
          component: () => import('../components/front/dining/FrontDiningView.vue')
        },
        {//新闻列表
          path: '/front/news/NewsListView',
          name: 'FrontNewsListView',
          component: () => import('../components/front/news/NewsList.vue')
        },
        {//新闻详情
          path: '/front/news/detail/:id',
          name: 'FrontNewsDetailView',
          component: () => import('../components/front/news/NewsDetail.vue')
        },
        {//健康管理首页
          path: '/front/health',
          name: 'FrontHealth',
          component: () => import('../components/front/health/HealthHome.vue'),
          meta: { requiresAuth: true, title: '健康管理' }
        },
        {//记录健康数据
          path: '/front/health/record',
          name: 'HealthRecord',
          component: () => import('../components/front/health/HealthRecord.vue'),
          meta: { requiresAuth: true, title: '记录健康数据' }
        },
        {//健康数据历史
          path: '/front/health/history',
          name: 'HealthHistory',
          component: () => import('../components/front/health/HealthHistory.vue'),
          meta: { requiresAuth: true, title: '健康数据历史' }
        },
        {//健康提醒设置
          path: '/front/health/reminder',
          name: 'HealthReminder',
          component: () => import('../components/front/health/HealthReminder.vue'),
          meta: { requiresAuth: true, title: '健康提醒设置' }
        },
        {//个人中心
          path: '/front/personal/PersonalCenter',
          name: 'PersonalCenter',
          component: () => import('../components/front/personal/PersonalCenter.vue')
        }
      ]
    },
    {
      path: '/MyView',
      name: 'MyView',
      component: MyView,
      children: [
        {//我的活动记录
          path: '/front/myActivity/MyActivityView',
          name: 'MyActivityView',
          component: () => import('../components/front/myActivity/MyActivityView.vue')
        },
        {//我的服务订单
          path: '/front/myService/MyServiceView',
          name: 'MyServiceView',
          component: () => import('../components/front/myService/MyServiceView.vue')
        },
        {//我的健康报告
          path: '/front/myReport/MyReportView',
          name: 'MyReportView',
          component: () => import('../components/front/myReport/MyReportView.vue')
        }
      ]
    }
  ]
})

//路由守卫
router.beforeEach((to, from, next) => {
  const menuStore = useMenuStore();
  menuStore.setCurrentpath(to);
  next()
});

export default router
